﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using ElectronicCommerce.Framework.Configuration;

namespace ElectronicCommerce.Framework.Payment.Configuration
{
    /// <summary>
    /// 支付类型集合
    /// </summary>
    public class PaymentModeCollection : KeyedCollection<string, PaymentMode>
    {
        /// <summary>
        /// 设置Key
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected override string GetKeyForItem(PaymentMode item)
        {
            return item.Code;
        }

        /// <summary>
        /// 根据支付方式名获取单个支付方式配置
        /// </summary>
        /// <param name="paymentModeName"></param>
        /// <returns></returns>
        public PaymentMode GetPaymentMode(string paymentModeCode)
        {
            return ConfigManager.GetConfig<PaymentConfig>().PaymentModes
                    .Where(p => p.Code.ToLower() == paymentModeCode.ToLower())
                    .SingleOrDefault();
        }
    }
}
